package com.ruoyi.project.data.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.data.mapper.WeightWorkerMapper;
import com.ruoyi.project.data.domain.WeightWorker;
import com.ruoyi.project.data.service.IWeightWorkerService;

/**
 * 人员信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-03-21
 */
@Service
public class WeightWorkerServiceImpl implements IWeightWorkerService 
{
    @Autowired
    private WeightWorkerMapper weightWorkerMapper;

    /**
     * 查询人员信息
     * 
     * @param id 人员信息ID
     * @return 人员信息
     */
    @Override
    public WeightWorker selectWeightWorkerById(Long id)
    {
        return weightWorkerMapper.selectWeightWorkerById(id);
    }

    /**
     * 查询人员信息列表
     * 
     * @param weightWorker 人员信息
     * @return 人员信息
     */
    @Override
    public List<WeightWorker> selectWeightWorkerList(WeightWorker weightWorker)
    {
        return weightWorkerMapper.selectWeightWorkerList(weightWorker);
    }

    /**
     * 新增人员信息
     * 
     * @param weightWorker 人员信息
     * @return 结果
     */
    @Override
    public int insertWeightWorker(WeightWorker weightWorker)
    {
        return weightWorkerMapper.insertWeightWorker(weightWorker);
    }

    /**
     * 修改人员信息
     * 
     * @param weightWorker 人员信息
     * @return 结果
     */
    @Override
    public int updateWeightWorker(WeightWorker weightWorker)
    {
        return weightWorkerMapper.updateWeightWorker(weightWorker);
    }

    /**
     * 批量删除人员信息
     * 
     * @param ids 需要删除的人员信息ID
     * @return 结果
     */
    @Override
    public int deleteWeightWorkerByIds(Long[] ids)
    {
        return weightWorkerMapper.deleteWeightWorkerByIds(ids);
    }

    /**
     * 删除人员信息信息
     * 
     * @param id 人员信息ID
     * @return 结果
     */
    @Override
    public int deleteWeightWorkerById(Long id)
    {
        return weightWorkerMapper.deleteWeightWorkerById(id);
    }

    @Override
    public String checkWorkerPhoneUnique(WeightWorker weightWorker) {
        int count = weightWorkerMapper.checkWorkerPhoneUnique(weightWorker);
        if (count > 0)
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public String checkWorkerIdCardUnique(WeightWorker weightWorker) {
        int count = weightWorkerMapper.checkWorkerIdCardUnique(weightWorker);
        if (count > 0)
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public int modifyPassword(WeightWorker weightWorker) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        weightWorker.setUpdateId(user.getUserId().toString());
        weightWorker.setUpdateTime(DateUtils.getNowDate());
        return weightWorkerMapper.modifyPassword(weightWorker);
    }

    @Override
    public void clearSpecialEquipmentPermissions(Long id) {
        weightWorkerMapper.clearSpecialEquipmentPermissions(id);
    }
}
